import 'package:flutter/material.dart';
import 'dart:math';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      backgroundColor: Colors.red,
      appBar: AppBar(
        title: const Text('Dicee',
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.red,

      ),
      body: const DicePage(),
    ),
  ));
}

class DicePage extends StatefulWidget {
  const DicePage({super.key});

  @override
  State<DicePage> createState() => _DicePageState();
}

class _DicePageState extends State<DicePage> {
  var leftNumber = 1;
  var rightNumber = 2;

  void changeDiceNumber() {
    setState(() {
      leftNumber = Random().nextInt(3) + 1;
      rightNumber = Random().nextInt(3) + 1;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: AlignmentDirectional.center, // 元素居中显示
      child: Row(
        children: [
          Expanded(child: TextButton(
              onPressed: (){
                changeDiceNumber();
              },
            child: Image.asset('images/dice$leftNumber.png'),
            ),
          ),
          // rightButton
          Expanded(child: TextButton(
            onPressed: (){
              changeDiceNumber();
            },
            child: Image.asset('images/dice$rightNumber.png'),
          ),
          )
        ],
      ),
    );
  }
}




